import 'dart:convert';
import 'package:ichinesereader/models/book/MaxScore.dart';
import 'package:ichinesereader/models/student/ProfileStudent.dart';

SelfReadingData selfReadingDataFromJson(String str) =>
    SelfReadingData.fromJson(json.decode(str));

String selfReadingDataToJson(SelfReadingData data) =>
    json.encode(data.toJson());

class SelfReadingData {
  SelfReadingData({
    this.limit,
    this.page,
    this.count,
    this.list,
  });

  int? limit;
  int? page;
  int? count;
  List<SelfReadingItem>? list;

  factory SelfReadingData.fromJson(Map<String, dynamic> json) =>
      SelfReadingData(
        limit: json["limit"],
        page: json["page"],
        count: json["count"],
        list: json["list"] != null
            ? List<SelfReadingItem>.from(
                json["list"].map((x) => SelfReadingItem.fromJson(x)))
            : null,
      );

  Map<String, dynamic> toJson() => {
        "limit": limit,
        "page": page,
        "count": count,
        "list": list != null
            ? List<dynamic>.from(list!.map((x) => x.toJson()))
            : null,
      };
}

class SelfReadingItem {
  SelfReadingItem({
    this.bookId,
    this.bookTitle,
    this.readCount,
    this.quizCount,
    this.maxScore,
    this.recording,
    this.writing,
    this.when,
    this.bookImageUrl,
    this.complete,
  });

  String? bookId;
  String? bookTitle;
  int? readCount;
  int? quizCount;
  MaxScore? maxScore;
  Writing? recording;
  Writing? writing;
  int? when;
  String? bookImageUrl;
  bool? complete;

  factory SelfReadingItem.fromJson(Map<String, dynamic> json) =>
      SelfReadingItem(
        bookId: json["bookId"],
        bookTitle: json["bookTitle"],
        readCount: json["readCount"],
        quizCount: json["quizCount"],
        maxScore: json["maxScore"] != null
            ? MaxScore.fromJson(json["maxScore"])
            : null,
        recording: json["recording"] != null
            ? Writing.fromJson(json["recording"])
            : null,
        writing:
            json["writing"] != null ? Writing.fromJson(json["writing"]) : null,
        when: json["when"],
        bookImageUrl: json["bookImageUrl"],
        complete: json["complete"],
      );

  Map<String, dynamic> toJson() => {
        "bookId": bookId,
        "bookTitle": bookTitle,
        "readCount": readCount,
        "quizCount": quizCount,
        "maxScore": maxScore != null ? maxScore!.toJson() : null,
        "recording": recording != null ? recording!.toJson() : null,
        "writing": writing != null ? writing!.toJson() : null,
        "when": when,
        "bookImageUrl": bookImageUrl,
        "complete": complete,
      };
}

class Writing {
  Writing({
    this.student,
    this.entry,
    this.status,
    this.lastReviewedAt,
    this.gradedAt,
    this.reviewer,
    this.gradedBy,
    this.sent,
    this.timestamp,
    this.grade,
    this.comment,
    this.playerContent,
    this.text,
    this.location,
  });

  ProfileStudent? student;
  String? entry;
  String? status;
  int? lastReviewedAt;
  int? gradedAt;
  Reviewer? reviewer;
  Reviewer? gradedBy;
  bool? sent;
  int? timestamp;
  String? grade;
  String? comment;
  String? playerContent;
  String? text;
  String? location;

  factory Writing.fromJson(Map<String, dynamic> json) => Writing(
        student: json["student"] != null
            ? ProfileStudent.fromJson(json["student"])
            : null,
        entry: json["entry"],
        status: json["status"],
        lastReviewedAt:
            json["lastReviewedAt"] != null ? json["lastReviewedAt"] : 0,
        gradedAt: json["gradedAt"] != null ? json["gradedAt"] : 0,
        reviewer: json["reviewer"] != null
            ? Reviewer.fromJson(json["reviewer"])
            : null,
        gradedBy: json["gradedBy"] != null
            ? Reviewer.fromJson(json["gradedBy"])
            : null,
        sent: json["sent"],
        timestamp: json["timestamp"] != null ? json["timestamp"] : 0,
        grade: json["grade"],
        comment: json["comment"],
        playerContent: json["playerContent"],
        text: json["text"],
        location: json["location"],
      );

  Map<String, dynamic> toJson() => {
        "student": student != null ? student!.toJson() : null,
        "entry": entry,
        "status": status,
        "lastReviewedAt": lastReviewedAt,
        "gradedAt": gradedAt,
        "reviewer": reviewer != null ? reviewer!.toJson() : null,
        "gradedBy": gradedBy != null ? gradedBy!.toJson() : null,
        "sent": sent,
        "timestamp": timestamp,
        "grade": grade,
        "comment": comment,
        "playerContent": playerContent,
        "text": text,
        "location": location
      };
}

class Reviewer {
  Reviewer({
    this.objectId,
    this.passwordHash,
    this.userName,
    this.email,
    this.salt,
    this.firstName,
    this.lastName,
    this.disabled,
    this.timestampDisabled,
    this.timestampEnabled,
    this.timestampCreated,
    this.timestampPasswordChanged,
    this.profileImageUrl,
    this.deleted,
    this.lastLoggedIn,
    this.lastLogIn,
    this.gender,
    this.address,
    this.city,
    this.state,
    this.country,
    this.userId,
    this.schoolName,
  });

  String? objectId;
  String? passwordHash;
  String? userName;
  String? email;
  String? salt;
  String? firstName;
  String? lastName;
  bool? disabled;
  int? timestampDisabled;
  int? timestampEnabled;
  int? timestampCreated;
  int? timestampPasswordChanged;
  String? profileImageUrl;
  bool? deleted;
  int? lastLoggedIn;
  int? lastLogIn;
  dynamic gender;
  dynamic address;
  dynamic city;
  dynamic state;
  dynamic country;
  String? userId;
  String? schoolName;

  factory Reviewer.fromJson(Map<String, dynamic> json) => Reviewer(
        objectId: json["objectId"],
        passwordHash: json["passwordHash"],
        userName: json["userName"],
        email: json["email"],
        salt: json["salt"],
        firstName: json["firstName"],
        lastName: json["lastName"],
        disabled: json["disabled"],
        timestampDisabled: json["timestampDisabled"],
        timestampEnabled: json["timestampEnabled"],
        timestampCreated: json["timestampCreated"],
        timestampPasswordChanged: json["timestampPasswordChanged"],
        profileImageUrl: json["profileImageUrl"],
        deleted: json["deleted"],
        lastLoggedIn: json["lastLoggedIn"],
        lastLogIn: json["lastLogIn"],
        gender: json["gender"],
        address: json["address"],
        city: json["city"],
        state: json["state"],
        country: json["country"],
        userId: json["userId"],
        schoolName: json["schoolName"],
      );

  Map<String, dynamic> toJson() => {
        "objectId": objectId,
        "passwordHash": passwordHash,
        "userName": userName,
        "email": email,
        "salt": salt,
        "firstName": firstName,
        "lastName": lastName,
        "disabled": disabled,
        "timestampDisabled": timestampDisabled,
        "timestampEnabled": timestampEnabled,
        "timestampCreated": timestampCreated,
        "timestampPasswordChanged": timestampPasswordChanged,
        "profileImageUrl": profileImageUrl,
        "deleted": deleted,
        "lastLoggedIn": lastLoggedIn,
        "lastLogIn": lastLogIn,
        "gender": gender,
        "address": address,
        "city": city,
        "state": state,
        "country": country,
        "userId": userId,
        "schoolName": schoolName,
      };
}
